package com.ruoyi.bizsys.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bizsys.mapper.AppUserPushMapper;
import com.ruoyi.bizsys.domain.AppUserPush;
import com.ruoyi.bizsys.service.IAppUserPushService;

/**
 * 用户推送记录Service业务层处理
 *
 * @author african-loan
 * @date 2021-09-10
 */
@Service
public class AppUserPushServiceImpl implements IAppUserPushService {
    @Autowired
    private AppUserPushMapper appUserPushMapper;

    /**
     * 查询用户推送记录
     *
     * @param id 用户推送记录ID
     * @return 用户推送记录
     */
    @Override
    public AppUserPush selectAppUserPushById(Long id) {
        return appUserPushMapper.selectAppUserPushById(id);
    }

    /**
     * 查询用户推送记录列表
     *
     * @param appUserPush 用户推送记录
     * @return 用户推送记录
     */
    @Override
    public List<AppUserPush> selectAppUserPushList(AppUserPush appUserPush) {
        return appUserPushMapper.selectAppUserPushList(appUserPush);
    }

    /**
     * 新增用户推送记录
     *
     * @param appUserPush 用户推送记录
     * @return 结果
     */
    @Override
    public int insertAppUserPush(AppUserPush appUserPush) {
        appUserPush.setCreateTime(DateUtils.getNowDate());
        return appUserPushMapper.insertAppUserPush(appUserPush);
    }

    /**
     * 修改用户推送记录
     *
     * @param appUserPush 用户推送记录
     * @return 结果
     */
    @Override
    public int updateAppUserPush(AppUserPush appUserPush) {
        appUserPush.setUpdateTime(DateUtils.getNowDate());
        return appUserPushMapper.updateAppUserPush(appUserPush);
    }

    /**
     * 批量删除用户推送记录
     *
     * @param ids 需要删除的用户推送记录ID
     * @return 结果
     */
    @Override
    public int deleteAppUserPushByIds(Long[] ids) {
        return appUserPushMapper.deleteAppUserPushByIds(ids);
    }

    /**
     * 删除用户推送记录信息
     *
     * @param id 用户推送记录ID
     * @return 结果
     */
    @Override
    public int deleteAppUserPushById(Long id) {
        return appUserPushMapper.deleteAppUserPushById(id);
    }

    @Override
    public int appUserPush(String userId, String pushTypeScore) {
        AppUserPush appUserPush = new AppUserPush();
        appUserPush.setUserId(userId);
        appUserPush.setPushType(AppUserPush.PUSH_TYPE_SCORE);
        List<AppUserPush> appUserPushes = this.selectAppUserPushList(appUserPush);
        if (appUserPushes.size() > 0){
            return 0;
        }
        return insertAppUserPush(appUserPush);
    }
}
